<template>
	<view class="kspljd">
		<video v-if="dijige==1"id="video1" class="shipin"   src="https://fd.aigei.com/src/vdo/mp4/95/951b4c3d01e54beaa08019880cfe73cd.mp4?e=1731571260&token=P7S2Xpzfz11vAkASLTkfHN7Fw-oOZBecqeJaxypL:3eGttVhHcL6ZaBxKt2joI3qovEU=" :controls="false" autoplay="true" loop="true"></video>
		<video v-else-if="dijige==2"id="video2" class="shipin"  src="https://fd.aigei.com/src/vdo/mp4/95/951b4c3d01e54beaa08019880cfe73cd.mp4?e=1731571260&token=P7S2Xpzfz11vAkASLTkfHN7Fw-oOZBecqeJaxypL:3eGttVhHcL6ZaBxKt2joI3qovEU=" :controls="false" autoplay="true" loop="true"></video>
		<video v-else-if="dijige==3"id="video3" class="shipin"  src="https://fd.aigei.com/src/vdo/mp4/95/951b4c3d01e54beaa08019880cfe73cd.mp4?e=1731571260&token=P7S2Xpzfz11vAkASLTkfHN7Fw-oOZBecqeJaxypL:3eGttVhHcL6ZaBxKt2joI3qovEU=" :controls="false" autoplay="true" loop="true"></video>
		<video v-else-if="dijige==0"id="video0" class="shipin"  src="https://fd.aigei.com/src/vdo/mp4/95/951b4c3d01e54beaa08019880cfe73cd.mp4?e=1731571260&token=P7S2Xpzfz11vAkASLTkfHN7Fw-oOZBecqeJaxypL:3eGttVhHcL6ZaBxKt2joI3qovEU=" :controls="false" autoplay="true" loop="true"></video>
		<button class="jieshu" type="warn" @click="jieshu">关闭视频</button>
		<view class="miaohexiayige">
			<div v-if="xiayige===0" class="miao">{{miao}}</div>
		   <button v-else-if="xiayige===1" class="xiayigeshipin" type="primary" @click="xiageshipin">下一个视频</button>
		</view>
		
		
	</view>
</template>

<script>
	export default {
		data() {
			return {
		        kj:'',
				miao:30,
				ab:true,
				xiayige:0,
				dijige:0,
				zhang:"aa"
			}
		},
		created(){
			 let now = new Date()
			  let nian=now.getFullYear()
			  let yue =now.getMonth()+1
			  let ri =now.getDate()
			 this.kj=uni.createVideoContext("video")
			  uni.request({
			  	url:"http://124.221.104.5:8080/huodong/update",
			  	data:{zhang:this.zhang,yue:yue,ri:ri,nian:nian},
			  	success:(res)=> {
			  		if(res.data.shipincishu==3)
					{ this.kj=uni.createVideoContext("video3")
					  this.dijige=3
					  }
					 else if(res.data.shipincishu==2)
					  {this.kj=uni.createVideoContext("video2")
					  this.dijige=2
					  }
					  else if(res.data.shipincishu==1)
					{  this.kj=uni.createVideoContext("video1")
					    this.dijige=1
						}
						else if(res.data.shipincishu==0)
						{  this.kj=uni.createVideoContext("video0")
						    this.dijige=0
							this.xiayige=-1
							}
						if(this.dijige>0)
						   this.jishi()
			  	},
			  
			  });
			  
			  
			 
		},
		methods: {
		async jishi(){
				for(this.miao;this.miao>0;this.miao--){
				    
				  if(this.ab==false)
				  {
					  this.kj.pause()
					 break
				  }
				  await new Promise((res)=>setTimeout(res,1000))
				  if(this.miao==1)
				  this.xiayige=1
			      
			  }
			},
		    xiageshipin(){
				this.miao=30
				this.xiayige=0
				this.dijige-=1
				if(this.dijige>=0)
				{   this.jishi()
					uni.request({
					url:"http://124.221.104.5:8080/huodong/kanshipinlingjindou",
					data:{zhang:this.zhang},
					complete: (res) => {
						
					}
				});
					
				}
				
			},
			 jieshu(){
				 this.kj.pause()
				 this.ab=false
				 if(this.dijige>0)
				{ uni.showModal({
				 	content:"再看"+this.miao+"秒就可以领取金豆了",
					 cancelText:"继续观看",
					 confirmText:"关闭视频",
					success: (res) => {
						if(res.confirm)
						uni.redirectTo({
							url:"/pages/index/yemian/zhuye"
						})
						else if(res.cancel)
						{   this.ab=true
							this.kj.play()
						    this.jishi()
						}
					}
				 })}
				 else if(this.dijige==0)
				 {
					 	uni.redirectTo({
					 		url:"/pages/index/yemian/zhuye"
					 	})
				
			}
			}
			
			
		}
	}
</script>

<style>
	.kspljd{
		width: 420rpx;
		height: 320rpx;
		position: absolute;
		left: 50%;
		top: 50%;
		transform: translate(-50%,-50%);
		background-color: aquamarine;
	}
	.kaishi{
		width: 150rpx;
		height: 50rpx;
		
	}
	.jieshu{
		width: 50rpx;
		height: 50rpx;
	}
	.shipin{
		width: 100%;
		
	
		
	}
	.miaohexiayige{
		 margin-top: 10rpx;
		 display: flex;
		 justify-content: center;
		 align-items: center;
		 position: relative;
	}
	.miao,.xiayigeshipin{
		position: absolute;
	}
	

</style>
